<script setup>
import { ref, onMounted } from 'vue';

const isVisible = ref(false);
const sectionRef = ref(null);
const email = ref('');

const submitForm = () => {
  // 表单提交逻辑
  console.log('提交邮箱:', email.value);
  email.value = '';
};

onMounted(() => {
  const observer = new IntersectionObserver((entries) => {
    entries.forEach(entry => {
      if (entry.isIntersecting) {
        isVisible.value = true;
        observer.disconnect();
      }
    });
  }, { threshold: 0.2 });
  
  if (sectionRef.value) {
    observer.observe(sectionRef.value);
  }
});
</script>

<template>
  <section ref="sectionRef" class="service-section">
    <div class="service-container" :class="{ 'animate': isVisible }">
      <!-- 背景装饰元素将通过CSS设置 -->
      
      <div class="content-wrapper">
        <div class="text-container">
          <h2 class="service-title">如有疑问，我们有24小时客服为您服务</h2>
          
          <form @submit.prevent="submitForm" class="email-form">
            <input 
              type="email" 
              v-model="email" 
              placeholder="Enter your email" 
              required
              class="email-input"
            />
            <button type="submit" class="submit-btn">联系我们</button>
          </form>
        </div>
      </div>
    </div>
  </section>
</template>

<style scoped>
.service-section {
  width: 100%;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #fff;
  padding: 40px 20px;
}

.service-container {
  width: 100%;
  max-width: 1296px;
  height: 376px;
  background-color: #00c389;
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.6s ease-out;
}

.service-container.animate {
  opacity: 1;
  transform: translateY(0);
}

.content-wrapper {
  display: flex;
  height: 100%;
  position: relative;
  z-index: 10;
  padding: 0 60px;
}

.text-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-left: auto;
  width: 50%;
}

.service-title {
  color: white;
  font-size: 2.4rem;
  font-weight: 700;
  margin-bottom: 30px;
  line-height: 1.3;
}

.email-form {
  display: flex;
  max-width: 500px;
}

.email-input {
  flex: 1;
  height: 54px;
  border: none;
  border-radius: 8px;
  padding: 0 20px;
  font-size: 1rem;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.submit-btn {
  height: 54px;
  background-color: #f05045;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0 24px;
  margin-left: 15px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.submit-btn:hover {
  background-color: #d83b30;
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

/* 背景图片设置 */
.service-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  background-image: url('@/assets/CS-bg.png');
  background-size: 100% 100%;
  background-position: left center;
  background-repeat: no-repeat;
  opacity: 0.9;
}

/* 左侧半透明遮罩，增强视觉效果 */
.service-container::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 50%;
  height: 100%;
  background: linear-gradient(to right, rgba(0, 195, 137, 0.1), rgba(0, 195, 137, 0.9));
  z-index: 2;
}

@media (max-width: 992px) {
  .service-container {
    height: auto;
    min-height: 376px;
  }
  
  .service-container::before {
    opacity: 0.3; /* 让背景图片在小屏幕上变淡，以便文本更清晰 */
  }
  
  .service-container::after {
    width: 100%;
    background: linear-gradient(to bottom, rgba(0, 195, 137, 0.2), rgba(0, 195, 137, 0.8));
  }
  
  .content-wrapper {
    flex-direction: column;
    padding: 40px;
  }
  
  .text-container {
    width: 100%;
    margin-left: 0;
  }
  
  .service-title {
    font-size: 2rem;
  }
}

@media (max-width: 576px) {
  .service-section {
    padding: 20px 15px;
  }
  
  .content-wrapper {
    padding: 30px 20px;
  }
  
  .service-title {
    font-size: 1.6rem;
  }
  
  .email-form {
    flex-direction: column;
  }
  
  .email-input {
    width: 100%;
    margin-bottom: 15px;
  }
  
  .submit-btn {
    width: 100%;
    margin-left: 0;
  }
}
</style> 